﻿Public Class Child

    Inherits Person


    Private _State As Integer

    Public Overrides Function Save() As Boolean
        Throw New NotImplementedException
    End Function

    Public Property State() As Integer
        Get
            Return _State
        End Get
        Set(ByVal value As Integer)
            _State = value
        End Set
    End Property

    Public Overrides Sub AddNote(ByVal oNote As Note)
        Dim params As New List(Of IDataParameter)
        Dim param As IDataParameter

        param = DatabaseLayer.DatabaseManager.InputParameter("NoteId", DbType.Int32, oNote.Id)
        params.Add(param)

        param = DatabaseLayer.DatabaseManager.InputParameter("ChildId", DbType.Int32, Id)
        params.Add(param)


        Dim ret As Integer = DatabaseLayer.DatabaseManager.StoredProc("uspAddChildNote", params, User.CurrentUser.ID)
        If ret = 0 Then
            Throw New Exception("Unable to Add Note.")
        End If

    End Sub

    Public Overrides ReadOnly Property Notes As List(Of Note)
        Get
            Dim dt As New DataTable
            Dim params As New List(Of IDataParameter)
            Dim iNoteId As Integer
            Dim oNote As Note
            Dim oNotesList As List(Of Note) = Nothing
            Dim param As IDataParameter = DatabaseLayer.DatabaseManager.InputParameter("ChildId", DbType.Int32, Id)
            params.Add(param)
            Dim ret As Integer = DatabaseLayer.DatabaseManager.StoredProc("uspGetChildNotes", params, dt, User.CurrentUser.ID)

            If ret > 0 Then
                oNotesList = New List(Of Note)
                For Each row As DataRow In dt.Rows
                    iNoteId = DirectCast(row("NoteId"), Integer)
                    oNote = Note.Load(iNoteId)
                    oNotesList.Add(oNote)
                Next
            End If

            Return oNotesList

        End Get
    End Property

    Public Shared Function Load(ByVal ChildId As Integer) As Child

        Dim oChild As New Child
        Dim params As New List(Of IDataParameter)
        Dim dt As New DataTable

        Dim param As IDataParameter = DatabaseLayer.DatabaseManager.InputParameter("childId", DbType.Int32, ChildId)
        params.Add(param)

        Dim ret As Integer = DatabaseLayer.DatabaseManager.StoredProc("uspGetChild", params, dt, User.CurrentUser.ID)
        If dt.Rows.Count > 0 Then
            Dim row As DataRow = dt.Rows(0)
            With oChild
                .DateOfBirth = DirectCast(row("DateOfBirth"), Date)
                .Gender = row("GenderId")
                .Id = ChildId
                .Name = row("Name")
                .State = row("stateid")
            End With
        End If

        Return oChild

    End Function

End Class
